package quirk;

/**
 * This class represents a query passed in by the user. It's really just 
 * a wrapper for a TermList with some info about the allowed query grammar.
 * 
 * @author Andrew Bernard
 */
public class Query {
  private TermList termList;
  
  /**
   * Constructor. Creates a list of all the atoms in the query. 
   * @param query
   */
  public Query(String query) {
    checkGrammar(query);
    termList = new TermList(query);
  }
  
  /**
   * Applies the pattern of this query to the mapping of words.
   * For example
   *    mapping1 = [true] [false] [true]
   *    mapping2 = [true] [false] [false]
   *    
   *    If this object's query pattern was: WORD1 (WORD2 | WORD3)    
   *    then this method would return true for mapping1 and
   *    false for mapping2
   *    
   * @param mapping   an array of Word objects corresponding to a line in a file 
   * @return the value of this query's pattern applied to the mapping
   */
  public boolean evaluate(QueryWord[] mapping) {
    return termList.evaluate(mapping);
  }
  
  private void checkGrammar(String query) {
    
  }
        
  /** Tests if the character is part of the BNF grammar used to form queries */
  public static boolean isGrammar(int ch) {
    return ch == '(' || ch == ')' || ch == '|' || ch == ' ';    
  }
}
